package lq.cloud.febsservertest.configure;

import lq.common.handler.StudyAccessDeniedHandler;
import lq.common.handler.StudyAuthExceptionEntryPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

/**
 * @program: cloud-study
 * @description:
 * @author: LQ
 * @create: 2020-09-23 17:38
 */
@Configuration
@EnableResourceServer
public class StudyServerTestResourceServerConfigure extends ResourceServerConfigurerAdapter {

    @Autowired
    private StudyAccessDeniedHandler accessDeniedHandler;
    @Autowired
    private StudyAuthExceptionEntryPoint authExceptionEntryPoint;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .requestMatchers().antMatchers("/**")
                .and()
                .authorizeRequests()
                .antMatchers("/**").authenticated();
    }
    /**
     * 重写异常处理
     * @param resource
     */
    @Override
    public void configure(ResourceServerSecurityConfigurer resource){
        resource.authenticationEntryPoint(authExceptionEntryPoint).accessDeniedHandler(accessDeniedHandler);
    }
}
